<!--
author:        yangmingchao <amustlang_yang@foxmail.com>
date:          2024-01-30 22:02:18
component:     index
Copyright © YourCompanyName All rights reserved
-->


<template>
    <span>
        <el-button type="primary" :link="link" plain icon="Avatar" @click="handleAdd" :disabled="disabled" style="margin: 0 10px;">
            <slot></slot>
        </el-button>
        <el-dialog v-model="reviewOpen" title="审核" width="50%" append-to-body class="dialogclass">
            <el-form ref="form2" :model="form" :rules="rules" label-width="100px">
                <el-form-item label="审核状态" prop="auditStatus" class="ml-4">
                    <el-radio-group v-model="form.auditStatus">
                        <el-radio label="1" size="large">同意</el-radio>
                        <el-radio label="2" size="large">不同意</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item v-if="form.auditStatus == 2" label="审核描述" prop="nopassMsg">
                    <el-input v-model="form.nopassMsg" type="textarea" placeholder="请输入内容" />
                </el-form-item>
            </el-form>
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="reviewOpenSubmit">确 定</el-button>
                    <el-button @click="reviewOpen = false">取 消</el-button>
                </div>
            </template>
        </el-dialog>
    </span>
</template>

<script>
// 审核按钮
export default {
    name: 'ReviewButton',
    props: {
        disabled: { type: Boolean, default: false },
        // 是否文字类型按钮
        link: { type: Boolean, default: false }
    },
    data() {
        return {
            reviewOpen: false,
            form: {
                // 审核状态
                auditStatus: '1',
                // 拒绝描述
                nopassMsg: null,
            },
            rules: {
                auditStatus: [
                    { required: true, message: "选择审核类型", trigger: "blur" }
                ],
                nopassMsg: [
                    { required: true, message: "请输入原因", trigger: "blur" }
                ],
            }
        }
    },
    methods: {
        handleAdd() {
            this.reviewOpen = true;
        },
        reviewOpenSubmit() {
            this.$refs["form2"].validate(valid => {
                if (valid) {
                    this.$emit('submit', this.form);
                    this.reviewOpen = false;
                }
            })

        }
    }

}
</script>

<style lang='scss'>
.dialogclass>.el-dialog__body {
    padding: 0 10px !important;
}
.el-radio.el-radio--large{
    height: auto;
}
</style>
